package java_class_work.week05.SendAndCopy;

import java.io.IOException;
import java.io.PipedInputStream;

/**
 * @Auther: admin
 * @Date: 2022/10/11 11:26
 * @Description:
 */
public class Copy implements Runnable {
    private PipedInputStream pis;

    public Copy() {
        this.pis = new PipedInputStream();
    }

    public PipedInputStream getPis() {
        return pis;
    }

    @Override
    public void run() {
        byte[] bytes = new byte[1024];
        try {
            int len = pis.read(bytes);
            // 接收并输出内容
            System.out.println(new String(bytes,0,len));
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                pis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
